package com.lixianhe.onlineexam.controller;

import com.lixianhe.onlineexam.pojo.Replay;
import com.lixianhe.onlineexam.service.ReplayService;
import com.lixianhe.onlineexam.util.ApiResultHandler;
import com.lixianhe.onlineexam.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ReplayController {
    @Autowired
    private ReplayService replayService;

    @PostMapping("replay")
    public R replay(@RequestBody Replay replay) {
        int i = replayService.addReplay(replay);
        if (i == 1) return ApiResultHandler.buildApiResult(200, "回复留言成功", i);
        return ApiResultHandler.buildApiResult(400, "回复留言失败", i);
    }

    @GetMapping("replay/{messageId}")
    public R selectById(@PathVariable("messageId") Integer messageId) {
        List<Replay> replays = replayService.selectById(messageId);
        return ApiResultHandler.buildApiResult(200, "查找留言", replays);
    }
}
